import {
  createRouter,
  createWebHistory,
  type RouteRecordRaw,
} from "vue-router";
import HomeView from "../views/ref&reactive.vue";

// 异步加载模块
// const views = import.meta.glob("../views/*.vue");
// console.log(views);
// const routes: Array<RouteRecordRaw> = [
//   {
//     path: "/",
//     name: "home",
//     component: HomeView,
//   },
// ];

// for (const key in views) {
//   routes.push({
//     path: key.slice(key.lastIndexOf("/"), key.lastIndexOf(".")),
//     component: views[key],
//     name: key.slice(key.lastIndexOf("/") + 1, key.lastIndexOf(".")),
//   });
// }

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "home",
      component: HomeView,
    },
    {
      path: "/about",
      name: "about",
      component: () => import("../views/AboutView.vue"),
    },
    {
      path: "/computed&watch",
      name: "computed&watch&watchEffect",
      component: () => import("../views/computed&watch.vue"),
    },
    {
      path: "/lifecycle",
      name: "生命周期",
      component: () => import("../views/lifecycle.vue"),
    },
    {
      path: "/communication",
      name: "组件",
      component: () => import("../views/communication.vue"),
    },
    {
      path: "/imageLazyLoading",
      name: "图片懒加载",
      component: () => import("../views/imageLazyLoading.vue"),
    },
    {
      path: "/hooks",
      name: "hooks",
      component: () => import("../views/hooks.vue"),
    },
    {
      path: "/global",
      name: "全局函数以及变量",
      component: () => import("../views/global.vue"),
    },
  ],
});

export default router;
